package observer;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: Alexander
 * Date: 09.07.12
 * Time: 15:29
 * To change this template use File | Settings | File Templates.
 */
public class WeatherData implements Subject {

    private ArrayList observers;
    private float temperature;
    private float pressure;
    private float humidity;

    public WeatherData(){
        observers = new ArrayList();
    }

    public void notifyObserver() {

        for (int i =0; i<observers.size(); i++){
            Observer o = (Observer) observers.get(i);
            o.update(temperature, pressure, humidity);
        }
    }

    public void registerObserver(Observer obs) {
        observers.add(obs);
    }

    public void deleteObserver(Observer observer) {

        int i = observers.indexOf(observer);
        if (i >= 0) observers.remove(observer);
    }

    public void measurementsChanged(){
        notifyObserver();
    }

    public void setMeasurements(float temp, float press, float humid){
        temperature = temp;
        pressure = press;
        humidity = humid;
        measurementsChanged();
    }
}
